﻿using System.Linq;
using SuCasa.Infrastructure;

namespace SuCasa.DataAccess{
    public interface IUserRepository {
        bool AddUser(User user);
        User GetUser(string userName, string password);
    }

    public class UserRepository : IUserRepository{
        readonly SuCasaDbContext _context;
        public UserRepository(SuCasaDbContext context)
        {
            _context = context;
        }

        public bool AddUser(User user){
            _context.Users.Add(user);
            return _context.SaveChanges() > 0;
        }

        public User GetUser(string userName, string password){
            var result = _context.Users.SingleOrDefault(x => x.UserName == userName && x.Password == password);
            return result;
        }
    }
}